package com.cly.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cly.domain.ProdComm;
import com.cly.service.ProdCommService;
import com.cly.vo.ProdCommOverview;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("prod/prodComm")
@Api(tags = "商品评论管理接口")
public class ProdCommController {

    @Autowired
    private ProdCommService prodCommService;

    @GetMapping("page")
    @ApiOperation("分页查询商品评论")
    @PreAuthorize("hasAuthority('prod:prodComm:page')")
    public ResponseEntity<Page<ProdComm>> findProdCommPage(Page<ProdComm> page, ProdComm prodComm){
        Page<ProdComm> prodCommPage = prodCommService.findProdCommPage(page, prodComm);
        return ResponseEntity.ok(prodCommPage);
    }


    //前台接口
    @GetMapping("prodComm/prodCommData")
    @ApiOperation("根据商品id查询商品评论总览")
    public ResponseEntity<ProdCommOverview> getProdCommOverview(Long prodId){
        ProdCommOverview prodCommOverview = prodCommService.getProdCommOverview(prodId);
        return ResponseEntity.ok(prodCommOverview);
    }

    @GetMapping("prodComm/prodCommPageByProd")
    @ApiOperation("根据商品id分页查询商品评论")
    public ResponseEntity<Page<ProdComm>> getProdCommPage(Long prodId, Page<ProdComm> page, Integer evaluate){
        Page<ProdComm> prodCommPage = prodCommService.getProdCommPage(prodId,page,evaluate);
        return ResponseEntity.ok(prodCommPage);
    }
}
